// pages/sell_orderdetail/sell_orderdetail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    order: '',
    add_address: '+请在此添加地址',
    kaidanren: '朱凯',
    gendanren: '朱凯',
    time: '2018-1-2 14:20',
    ishiddenedit_address: true,//是否隐藏地址重填框
    ishiddenedit_gendanren: true,//是否隐藏跟单人输入框
    inputaddress: '',
    inputgendanren: '',
    yingfukuan: 10000,
    shoukuan: 0,
    jieqian: 10000,
    shifouzhankai: [],
    orderid: '',
    kuanxiang: [{ 'zhanghu': 'hahaha', 'operate': '收款', 'shumu': 123 }, { 'zhanghu': 'hahaha', 'operate': '收款', 'shumu': 123 }, { 'zhanghu': 'hahaha', 'operate': '收款', 'shumu': 123 }, { 'zhanghu': 'hahaha', 'operate': '收款', 'shumu': 123 }, { 'zhanghu': 'hahaha', 'operate': '收款', 'shumu': 123 }],
    bendanyaohuo: [
      {
        'operate':'展开','image': '../../images/33.png', 'number': 10, 'name': 'haha', 'price': 30, 'detail': [{ 'color': '黑色', 'size': 'xl', 'yaohuo': 6, 'isqianhuo': true }]
      },
      { 'operate': '展开','image': '', 'number': 20, 'name': 'haha', 'price': 30, 'detail': [{ 'color': '白色', 'size': 'xl', 'yaohuo': 6, 'isqianhuo': true }, { 'color': '黑色', 'size': 'xl', 'yaohuo': 6, 'isqianhuo': true }] }
    ]
  },
  onLoad: function () {
    console.log("传到detail的one" + wx.getStorageSync("one"))
    console.log(wx.getStorageSync("one").orderid)
    var tm = []
    var len = this.data.bendanyaohuo.length
    for(var i = 0 ; i < len ; i++){
      tm.push(true)
    }
    this.setData({
      one: wx.getStorageSync("one"),
      add_address: wx.getStorageSync("one").address,
      gendanren: wx.getStorageSync("one").gendanren,
      orderid: wx.getStorageSync("one").orderid,
      kuanxiang: wx.getStorageSync("shoukuanfangshi"),
      shifouzhankai:tm
    })
  },
  add_address: function () {
    this.setData({
      ishiddenedit_address: false
    })

  },

  edit_gendanren: function () {
    this.setData({
      ishiddenedit_gendanren: false
    })

  },

  cancel_address: function () {
    this.setData({
      ishiddenedit_address: true
    });
  },

  cancel_gendanren: function () {
    this.setData({
      ishiddenedit_gendanren: true
    });
  },

  getvalue_address: function (e) {
    this.setData({
      inputaddress: e.detail.value
    })
  },//获取地址弹框输入信息

  getvalue_gendanren: function (e) {
    this.setData({
      inputgendanren: e.detail.value
    })
  },//获取跟单人弹框输入信息

  confirm_address: function () {//修改地址方法***
    console.log("修改后地址" + this.data.inputaddress)
    this.setData({
      ishiddenedit_address: true,
      add_address: this.data.inputaddress
    })
    var that = this;
    wx.request({
      url: 'https://www.wenzhixinxi.com/phptest/updateaddress.php', //仅为示例，并非真实的接口地址
      data: {
        id: that.data.orderid,
        address: that.data.inputaddress
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log("修改完毕");
        console.log(that.data.orderid);
        console.log(that.data.inputaddress);
        console.log(res.data);
      }
    })
  },

  confirm_gendanren: function () {//修改跟单人方法***
    console.log(this.data.inputgendanren)
    this.setData({
      ishiddenedit_gendanren: true,
      gendanren: this.data.inputgendanren
    })
    console.log("跟单人" + this.data.inputgendanren)
    this.setData({
      ishiddenedit_gendanren: true,
      gendanren: this.data.inputgendanren
    })
    var that = this;
    wx.request({
      url: 'https://www.wenzhixinxi.com/phptest/updategendanren.php', //仅为示例，并非真实的接口地址
      data: {
        id: that.data.orderid,
        gendanren: that.data.inputgendanren
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log("修改完毕");
        console.log(that.data.orderid);
        console.log(that.data.inputgendanren);
        console.log(res.data);
      }
    })
  },

  zhankai: function (e) {
    var index=e.currentTarget.dataset.index;
    console.log(this.data.shifouzhankai[index] )
    if (this.data.shifouzhankai[index] == true)
    {
      this.data.shifouzhankai[index] = false
      this.data.bendanyaohuo[index].operate = '收回'
      this.setData({
        shifouzhankai: this.data.shifouzhankai,
        bendanyaohuo: this.data.bendanyaohuo
      })
    }
    else{
      this.data.shifouzhankai[index] = true
      this.data.bendanyaohuo[index].operate = '展开'
      this.setData({
        shifouzhankai: this.data.shifouzhankai,
        bendanyaohuo: this.data.bendanyaohuo
      })
    }
  },

  xinzengshoukuan:function(){
    wx.navigateTo({
      url: '../sell_addcheckout/sell_addcheckout',
      success: function(res) {
        console.log("yes")
      },
      fail: function (res) { console.log("no")},
      complete: function(res) {},
    })
  }
})